class Permission < ActiveRecord::Base
	belongs_to :role
	
	def allows?(object, operation)
		object_permission = Permission::String.new(object_name)
		operation_permission = Permission::String.new(operation_name)
		object_permission.matches?(object) && operation_permission.matches?(operation)
  end		
		
	class String < ::String
		def regexp?
			self.index("/") == 0 and self.rindex("/") == self.length - 1 and self.length > 2
		end
		def matches? other
			if regexp?
				regexp_text = self[1, self.length - 2]
				return other.match(regexp_text) != nil
			else
				return other == self
			end
	  end
	end
end

